<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/19
 * Time: 18:09
 */

namespace Game\Library;


use Game\Config\Config;

use Workerman\MySQL\Connection;

class Mysql
{
    /** @var Connection */
    private static $instance;

    public static function getInstance():Connection
    {
        if(!isset(self::$instance)){
            self::$instance =  new Connection(Config::DB_Host, Config::DB_Port, Config::DB_User,Config::DB_Password, Config::DB_Name, Config::DB_Charset);
        }
        return self::$instance;
    }

    /**
     * 关闭数据库实例
     */
    public static function closeConnection(){
        if(isset(self::$instance)) {
            self::$instance->closeConnection();
            self::$instance = null;
        }
    }
}